/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.dbcp.BasicDataSource;


/**
 *
 * @author pyty
 */
public class Test {
    public static void main (String args[]) {
//        Properties props = new Properties();
//
//        URL url = ClassLoader.getSystemResource("dbconfig.properties");
//        //ClassLoader.getSystemResource(null)
//        try {
//            props.load(url.openStream());
//            
//        } catch (IOException ex) {
//            //throw new RuntimeException("Error opening DB config file", ex);
//            System.err.println("CHYBA");
//        }
//        
//        System.out.println("DB name: " + props.getProperty("dbname"));
//        System.out.println("DB user: " + props.getProperty("dbuser"));
//        System.out.println("DB pass: " + props.getProperty("dbpass"));
//        System.out.println("");
//        
//        DBConfig dbc = new DBConfig();
//        
//        System.out.println("DB url: " + dbc.getDbUrl());
//        System.out.println("DB user: " + dbc.getDbUser());
//        System.out.println("DB pass: " + dbc.getDbPass());
//        System.out.println("DB driver: " + dbc.getDbDriver());
        
        MediumManagerImpl mediumManager = new MediumManagerImpl();
        List<Medium> mediums;
        
        //try {
            DBConfig dbConfig = new DBConfig();

            BasicDataSource ds = new BasicDataSource();
            ds.setUrl(dbConfig.getDbUrl());
            ds.setUsername(dbConfig.getDbUser());
            ds.setPassword(dbConfig.getDbPass());

            ds.setDriverClassName(dbConfig.getDbDriver());

            mediumManager.setDataSource(ds);
            
            mediums = mediumManager.searchMediumsByString("UP".toLowerCase());
            
        //} catch (SQLException ex) {
        //    throw new RuntimeException("DB Error",ex);
        //}
        
        for(Medium m : mediums) {
            System.out.println(m.getId() + "\t" + m.getName() + "\t" + m.getAuthor() + "\t" + m.getDescription()); 
        }
    }
}
